package ue.a5;

import gdp.stdlib.StdIn;

/*************************************************************************
 * Compilation: javac HammingEncoder.java StdIn.java Execution: java
 * HammingEncoder < all4.txt
 *
 * Read in sequences of 4 bits at a time from stdin, compute 3 parity bits for
 * Hamming code, and print resulting 7 bits to stdout.
 *
 *
 *************************************************************************/

public class HammingEncoder {

	// return an integer corresponding to the 4 digit hex string
	public static int fromHex(String s) {
		return Integer.parseInt(s, 16) & 0xFFFF;
	}

	public static void main(String[] args) {
		while (!StdIn.isEmpty()) {
			int m1 = fromHex(StdIn.readString());
			if (m1 == 0xFFFF) {
				break;
			}
			int m2 = fromHex(StdIn.readString());
			int m3 = fromHex(StdIn.readString());
			int m4 = fromHex(StdIn.readString());

			// compute parity bits
			int p1 = m1 ^ m2 ^ m4;
			int p2 = m1 ^ m3 ^ m4;
			int p3 = m2 ^ m3 ^ m4;

			// print results
			// System.out.print(m1 + " " + m2 + " " + m3 + " " + m4 + " ");
			// System.out.print(p1 + " " + p2 + " " + p3);
			// System.out.println();

			// to print results the way the .toy program does
			// uncomment the next two print statements
			// and comment out the above three print statements
			System.out.println("000" + m1 + "\n000" + m2 + "\n000" + m3 + "\n000" + m4);
			System.out.println("000" + p1 + "\n000" + p2 + "\n000" + p3);

		}
	}
}
